<template>
	<b-layout-shop :tabActive="2" :type="2" :total="paymentAmount" @action="goPayNav">
		<navbar bgcolor="#fff" :back="false" :title="$t('商品')"></navbar>
		<view class="bg-white">
			<view class="">
				<shop-card-selected @action="selectedShop" :item="item" v-for="(item,index) in datalist" />
			</view>

		</view>
	</b-layout-shop>
</template>

<script>
	import {
		myNotify
	} from "@/api/notify.js"
	export default {
		data() {
			var shopbuylist = uni.getStorageSync("shopbuylist") || []
			return {
			
				datalist: shopbuylist,
				shoplist: {},
				paymentAmount: 0,
				discountAmount: 0,
				totalAmount: 0,
				quantity: 0,
			}
		},
		onLoad() {
			uni.removeStorageSync("shopStorege")
			//this.getData();
		},
		onShow() {
					var shopbuylist = uni.getStorageSync("shopbuylist") || []
					this.datalist=shopbuylist
		},
		methods: {
			// getData: function() {
			// 	var the = this;
			// 	myNotify().then(res => {
			// 		console.log(res)
			// 		the.datalist = res;
			// 	})
			// }
			goPayNav: function() {
				if (this.quantity > 0) {
					uni.navigateTo({
						url: "/page/workbench/pages/agent/buy"
					})
				}
			},
			selectedShop: function(e) {
				console.log("selectedShop:fun")
				console.log(e)
				var value = e.value;
				var item = e.item;
				this.paymentAmount = 0;
				this.discountAmount = 0;
				this.totalAmount = 0;
					this.quantity = 0;
				var a = {
					price: item.price,
					paymentAmount: (item.price * value),
					discountAmount: ((item.marketPrice - item.price) * value),
					totalAmount: (item.marketPrice * value),
					name: item.name,
					image: item.image,
					quantity: value,
					goodsId: item.id,
					brandId: item.brandId,
					categoryId: item.categoryId
				}
				this.shoplist[item.id] = a
				for (let var1 in this.shoplist) {
					var ai = this.shoplist[var1]
					//	this.priceAll = (value * item.price)
					this.paymentAmount = (this.paymentAmount + ai.paymentAmount);
					this.discountAmount = (this.discountAmount + ai.discountAmount);
					this.totalAmount = (this.totalAmount + ai.totalAmount);
					this.quantity = (this.quantity + ai.quantity);
					

				}

				this.priceAll = (value * item.price)
				console.log("selectedShop", this.shoplist)
				console.log("selectedShop", Object.values(this.shoplist))
				var shopStorege = {
					data: Object.values(this.shoplist),
					priceAll: this.paymentAmount,
					agentPrice: this.agentPrice,
					agentId: this.agentId,
					paymentAmount: this.paymentAmount,
					discountAmount: this.discountAmount,
					totalAmount: (item.marketPrice * value),
					quantity: this.quantity,
					type: 0
				}
				uni.setStorageSync("shopStorege", shopStorege)
			},
		
		}
	}



	
</script>

<style>
</style>